// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//


#pragma once

#include <pollux/dwio/common/selective_byte_rle_column_reader.h>
#include <pollux/dwio/parquet/reader/parquet_data.h>

namespace kumo::pollux::parquet {
    class BooleanColumnReader : public dwio::common::SelectiveByteRleColumnReader {
    public:
        using ValueType = bool;

        BooleanColumnReader(
            const TypePtr &requestedType,
            std::shared_ptr<const dwio::common::TypeWithId> fileType,
            ParquetParams &params,
            common::ScanSpec &scanSpec)
            : SelectiveByteRleColumnReader(
                requestedType,
                std::move(fileType),
                params,
                scanSpec) {
        }

        void seekToRowGroup(int64_t index) override {
            SelectiveByteRleColumnReader::seekToRowGroup(index);
            scanState().clear();
            readOffset_ = 0;
            formatData_->as<ParquetData>().seekToRowGroup(index);
        }

        uint64_t skip(uint64_t numValues) override {
            formatData_->as<ParquetData>().skip(numValues);
            return numValues;
        }

        void read(int64_t offset, const RowSet &rows, const uint64_t *incomingNulls)
        override {
            readCommon<BooleanColumnReader, true>(offset, rows, incomingNulls);
            readOffset_ += rows.back() + 1;
        }

        template<typename ColumnVisitor>
        void readWithVisitor(const RowSet & /*rows*/, ColumnVisitor visitor) {
            formatData_->as<ParquetData>().readWithVisitor(visitor);
        }
    };
} // namespace kumo::pollux::parquet
